#include"TcpServer.hpp"
#include"NetCal.hpp"
#include"Potorol.hpp"
#include"Daemon.hpp"
void Usage(const std::string &proc)
{
    std::cout<<"Usage: "<<proc <<" port"<<std::endl;
}

int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        Usage(argv[0]);
        exit(USAGE_ERROR);
    }

    //Daemon(0,0);
    daemon(0,0);

    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<Cal> cal = std::make_unique<Cal>();

    std::unique_ptr<Potorol> potorol = std::make_unique<Potorol>([&cal](Request &req){
        return cal->Excute(req);
    });



    std::unique_ptr<TcpServer> tser = std::make_unique<TcpServer>
    (port,[&potorol](std::shared_ptr<Socket>& sock,InetAddr &client){
        potorol->GetRequest(sock,client);
    });

    tser->Start();

    return 0;
}